﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Query.Implementation
{
    [Implements(typeof(ICaseExpression))]
    public class CaseExpression : ExpressionBase, ICaseExpression
    {
        private readonly IList<IWhenThenExpression> _whenExpressions = new List<IWhenThenExpression>();
        
        public IList<IWhenThenExpression> WhenExpressions
        {
            get { return _whenExpressions; }
        }

        public IExpression ElseExpression { get; set;}
        

        public ICaseExpression When(IExpression whenExpression, IExpression thenExpression)
        {
            var whenThenExpression = new WhenThenExpression() {When = whenExpression, Then = thenExpression};
            _whenExpressions.Add(whenThenExpression);
            return this;
        }

        public ExpressionBase Else(IExpression elseExpression)
        {
            ElseExpression = elseExpression;
            return this;
        }

        public ExpressionBase End()
        {
            return this;
        }
    }
}
